package com.yf.springboot.completablefuture;

import com.yf.springboot.util.FakeUtil;

import java.util.concurrent.CompletableFuture;

public class ThenCombine {
    public static void main(String[] args) {
        FakeUtil.printTimeAndThread("小白进入餐厅");
        FakeUtil.printTimeAndThread("小白点了 蕃茄炒蛋 + 一碗米饭");

        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
            FakeUtil.printTimeAndThread("厨师炒菜");
            FakeUtil.sleepMillis(3000);
            return "蕃茄炒蛋";
        }).thenCombine(CompletableFuture.supplyAsync(() -> {
            FakeUtil.printTimeAndThread("服务员蒸饭");
            FakeUtil.sleepMillis(2000);
            return "米饭";
        }), (dish, rice) -> {
            FakeUtil.printTimeAndThread("服务员打饭");
            FakeUtil.sleepMillis(1000);
            return String.format("%s + %s 好子", dish, rice);
        });

        FakeUtil.printTimeAndThread("小白开始打王者");
        FakeUtil.printTimeAndThread(String.format("%s, 小白开吃", cf1.join()));
    }
}
